package ru.fsd.sokoban;

import java.util.ArrayList;


/**
 * Представляет собой игровое поле.
 */
public class GameBoard {
	
	private GameObject[][] gameObjects;
	ArrayList<GameObject> objs = null;
	
	private Player player = null;

	
	public GameBoard(int cellNumberByX, int cellNumberByY) {
		gameObjects = new GameObject[cellNumberByX][cellNumberByY];
		clear();
	}
	
	public void setObjs(ArrayList<GameObject> objs) {
		this.objs = objs;
	}
	
	public GameObject getGameObject(int x, int y) {
		return gameObjects[x][y];
	}
	
	public void setGameObject(GameObject obj, int x, int y) {
		if(obj.getRole() == GameObject.PLAYER) {
			gameObjects[x][y] = objs.get(GameObject.GROUND);
			player.setPos(x, y);
		}
		else 
			gameObjects[x][y] = obj;
	}
	
	public void clear() {
		for(int i = 0; i < gameObjects.length; i++)
			for(int j = 0; j < gameObjects[i].length; j++)
				gameObjects[i][j] = null;		
	}
	
	public int getLengthByX() {
		return gameObjects.length;
	}
	
	public int getLengthByY() {
		return gameObjects[0].length;
	}
	
	public void setPlayer(Player player) {
		this.player = player;
	}
	
	public Player getPlayer() {
		return player;
	}
}
